package pages;

import org.openqa.selenium.WebElement;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import utils.BaseAction;

public class LoginPage {
	AndroidDriver driver;
	BaseAction action;
	public LoginPage(AndroidDriver driver) {
		this.driver=driver;
		action=new BaseAction(driver);
	}
	
	public WebElement input_username() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/et_account"));
	}
	
	public WebElement input_password() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/et_password"));
	}
	
	public WebElement btn_login() {
		return driver.findElement(AppiumBy.id("njust.dzh.fitnesssystem:id/btn_login"));
	}
	
	public void login(String username,String password) throws InterruptedException {
		action.type(this.input_username(), username);
		action.type(this.input_password(), password);
		action.click(this.btn_login());
	}
	
	public MainPage loginSuccess(String username,String password) throws InterruptedException {
		login(username,password);
		return new MainPage(driver);
	}
	
	public String loginFail(String username,String password) throws InterruptedException {
		login(username,password);
		return action.getToastMsg();
	}
}
